/////////////////////////////////////////////////////////////////////////////
// Name:        AeroDynamics_Diag.cpp
// Purpose:     Dialog for AeroDynamics
// Author:      Matthew Gong
// Created:     05/08/2005
// Copyright:   (c) Matthew Gong
// Licence:     GPL licence
/////////////////////////////////////////////////////////////////////////////

#ifdef __GNUG__
// #pragma implementation
#endif

// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif

// -*- C++ -*- generated by wxGlade 0.3.5.1 on Sun May  8 19:01:46 2005

#include "AeroDynamics_Diag.h"
#include "TreeItem.h"

BEGIN_EVENT_TABLE(AeroDynamicsDialog, wxDialog)
  EVT_CHECKBOX(ALPHA_LIMITS, AeroDynamicsDialog::OnEnableA)
  EVT_CHECKBOX(HYSTERESIS_LIMITS, AeroDynamicsDialog::OnEnableH)
END_EVENT_TABLE()

AeroDynamicsDialog::AeroDynamicsDialog(wxWindow* parent, int id, const wxString& title, const wxPoint& pos, const wxSize& size, long style):
    wxDialog(parent, id, title, pos, size, style)
{
    // begin wxGlade: AeroDynamicsDialog::AeroDynamicsDialog
    sizer_2_copy_staticbox = new wxStaticBox(this, -1, _("hysteresis limits"));
    sizer_2_staticbox = new wxStaticBox(this, -1, _("alpha limits"));
    checkbox_a_enable = new wxCheckBox(this, ALPHA_LIMITS, _("Enable"));
    label_a_min = new wxStaticText(this, -1, _("Min:"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_a_min = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC, &alpha_min));
    label_a_max = new wxStaticText(this, -1, _("Max:"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_a_max = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC, &alpha_max));
    checkbox_h_enable = new wxCheckBox(this, HYSTERESIS_LIMITS, _("Enable"));
    label_h_min = new wxStaticText(this, -1, _("Min:"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_h_min = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC, &hysteresis_min));
    label_h_max = new wxStaticText(this, -1, _("Max:"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_h_max = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC, &hysteresis_max));
    button_ok = new wxButton(this, wxID_OK, _("OK"));
    button_cancel = new wxButton(this, wxID_CANCEL, _("Cancel"));

    set_properties();
    do_layout();
    // end wxGlade
}


void AeroDynamicsDialog::set_properties()
{
    // begin wxGlade: AeroDynamicsDialog::set_properties
    label_a_min->SetMinSize(wxSize(50, -1));
    text_ctrl_a_min->SetMinSize(wxSize(80, -1));
    label_a_max->SetMinSize(wxSize(50, -1));
    text_ctrl_a_max->SetMinSize(wxSize(80, -1));
    label_h_min->SetMinSize(wxSize(50, -1));
    text_ctrl_h_min->SetMinSize(wxSize(80, -1));
    label_h_max->SetMinSize(wxSize(50, -1));
    // end wxGlade
}


void AeroDynamicsDialog::do_layout()
{
    // begin wxGlade: AeroDynamicsDialog::do_layout
    wxBoxSizer* sizer_1 = new wxBoxSizer(wxVERTICAL);
    wxBoxSizer* sizer_5 = new wxBoxSizer(wxHORIZONTAL);
    wxStaticBoxSizer* sizer_2_copy = new wxStaticBoxSizer(sizer_2_copy_staticbox, wxVERTICAL);
    wxBoxSizer* sizer_4_copy = new wxBoxSizer(wxHORIZONTAL);
    wxBoxSizer* sizer_3_copy = new wxBoxSizer(wxHORIZONTAL);
    wxStaticBoxSizer* sizer_2 = new wxStaticBoxSizer(sizer_2_staticbox, wxVERTICAL);
    wxBoxSizer* sizer_4 = new wxBoxSizer(wxHORIZONTAL);
    wxBoxSizer* sizer_3 = new wxBoxSizer(wxHORIZONTAL);
    sizer_2->Add(checkbox_a_enable, 0, wxALL, 3);
    sizer_3->Add(label_a_min, 0, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_3->Add(text_ctrl_a_min, 1, wxALL|wxALIGN_CENTER_VERTICAL, 5);
    sizer_2->Add(sizer_3, 1, wxEXPAND, 0);
    sizer_4->Add(label_a_max, 0, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_4->Add(text_ctrl_a_max, 1, wxALL|wxALIGN_CENTER_VERTICAL, 5);
    sizer_2->Add(sizer_4, 1, wxEXPAND, 0);
    sizer_1->Add(sizer_2, 0, wxALL|wxEXPAND, 5);
    sizer_2_copy->Add(checkbox_h_enable, 0, wxALL, 3);
    sizer_3_copy->Add(label_h_min, 0, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_3_copy->Add(text_ctrl_h_min, 1, wxALL|wxALIGN_CENTER_VERTICAL, 5);
    sizer_2_copy->Add(sizer_3_copy, 1, wxEXPAND, 0);
    sizer_4_copy->Add(label_h_max, 0, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_4_copy->Add(text_ctrl_h_max, 1, wxALL|wxALIGN_CENTER_VERTICAL, 5);
    sizer_2_copy->Add(sizer_4_copy, 1, wxEXPAND, 0);
    sizer_1->Add(sizer_2_copy, 0, wxALL|wxEXPAND, 5);
    sizer_5->Add(button_ok, 1, wxALL, 10);
    sizer_5->Add(button_cancel, 1, wxALL, 9);
    sizer_1->Add(sizer_5, 0, wxALL|wxEXPAND, 10);
    SetAutoLayout(true);
    SetSizer(sizer_1);
    sizer_1->Fit(this);
    sizer_1->SetSizeHints(this);
    Layout();
    // end wxGlade
}

void AeroDynamicsDialog::OnEnableA(wxCommandEvent & event)
{
  if (checkbox_a_enable->GetValue())
  {
    text_ctrl_a_min->Enable(true);
    text_ctrl_a_max->Enable(true);
  }
  else
  {
    text_ctrl_a_min->Enable(false);
    text_ctrl_a_max->Enable(false);
  }
}

void AeroDynamicsDialog::OnEnableH(wxCommandEvent & event)
{
  if (checkbox_h_enable->GetValue())
  {
    text_ctrl_h_min->Enable(true);
    text_ctrl_h_max->Enable(true);
  }
  else
  {
    text_ctrl_h_min->Enable(false);
    text_ctrl_h_max->Enable(false);
  }
}

void AeroDynamicsDialog::Load(const TreeItemData_aerodynamics * data)
{
  checkbox_a_enable->SetValue(data->has_alphalimits);
  //text_ctrl_a_min->SetValue(wxString::Format(wxT("%g"), data->alphaclmin));
  //text_ctrl_a_max->SetValue(wxString::Format(wxT("%g"), data->alphaclmax));
  alpha_max = wxString::Format(wxT("%g"), data->alphaclmax);
  alpha_min = wxString::Format(wxT("%g"), data->alphaclmin);
 
  checkbox_h_enable->SetValue(data->has_hysteresis_limits);
  //text_ctrl_h_min->SetValue(wxString::Format(wxT("%g"), data->alphahystmin));
  //text_ctrl_h_max->SetValue(wxString::Format(wxT("%g"), data->alphahystmax));
  hysteresis_max = wxString::Format(wxT("%g"), data->alphahystmax);
  hysteresis_min = wxString::Format(wxT("%g"), data->alphahystmin);
 
  if (checkbox_a_enable->GetValue())
  {
    text_ctrl_a_min->Enable(true);
    text_ctrl_a_max->Enable(true);
  }
  else
  {
    text_ctrl_a_min->Enable(false);
    text_ctrl_a_max->Enable(false);
  }
  if (checkbox_h_enable->GetValue())
  {
    text_ctrl_h_min->Enable(true);
    text_ctrl_h_max->Enable(true);
  }
  else
  {
    text_ctrl_h_min->Enable(false);
    text_ctrl_h_max->Enable(false);
  }
}

void AeroDynamicsDialog::Save(TreeItemData_aerodynamics * data)
{
  data->has_alphalimits = checkbox_a_enable->GetValue();
  //text_ctrl_a_min->GetValue().ToDouble(&(data->alphaclmin));
  //text_ctrl_a_max->GetValue().ToDouble(&(data->alphaclmax));
  alpha_min.ToDouble(&(data->alphaclmin));
  alpha_max.ToDouble(&(data->alphaclmax));
  
  data->has_hysteresis_limits = checkbox_h_enable->GetValue();
  //text_ctrl_h_min->GetValue().ToDouble(&(data->alphahystmin));
  //text_ctrl_h_max->GetValue().ToDouble(&(data->alphahystmax));
  hysteresis_min.ToDouble(&(data->alphahystmin));
  hysteresis_max.ToDouble(&(data->alphahystmax));
}

